/**
 * 
 */
package com.snapp.web.actions.permissions;

import javax.servlet.http.HttpServletRequest;

import org.jdom.Element;

import com.snapp.web.actions.secure.List;
import com.snapp.web.agents.AccessAgent;

/**
 * @author kile
 *
 */
public class GetTree extends List {

	public String execute(HttpServletRequest req) {
		// execute secure list
		String nxtPage = super.execute(req);
		
		if (getResultCode() > RESULT_CODE_ERROR) {
			// sort the list to nest tiers
			AccessAgent aa = new AccessAgent();
			Element stree = aa.sortFunctionTree(list, "0", null);
			// reset response body to sorted tree
			setBodyElement(stree);
			// rebuild the response
			return snappResponse(req);
		}
		
		return nxtPage;
		
	}
}
